package main

import (
	"github.com/opentracing/opentracing-go"
	"github.com/uber/jaeger-client-go"
	jaegercfg "github.com/uber/jaeger-client-go/config"
	"time"
)

func main() {
	cfg := jaegercfg.Configuration{
		Sampler: &jaegercfg.SamplerConfig{
			Type:  jaeger.SamplerTypeConst,
			Param: 1,
		},
		Reporter: &jaegercfg.ReporterConfig{
			LogSpans:           true,
			LocalAgentHostPort: "127.0.0.1:6831",
		},
		ServiceName: "order-service",
	}

	tracer, closer, err := cfg.NewTracer(jaegercfg.Logger(jaeger.StdLogger))
	if err != nil {
		panic(err)
	}
	defer closer.Close()

	opentracing.SetGlobalTracer(tracer)
	rootSpan := opentracing.StartSpan("order-span-grpc")
	span := opentracing.StartSpan("funA", opentracing.ChildOf(rootSpan.Context()))
	time.Sleep(time.Second)
	span.Finish()

	span2 := opentracing.StartSpan("funB", opentracing.ChildOf(rootSpan.Context()))
	time.Sleep(time.Second)
	span2.Finish()

	span3 := opentracing.StartSpan("funC", opentracing.ChildOf(rootSpan.Context()))
	time.Sleep(time.Second)
	span3.Finish()

	rootSpan.Finish()

}
